<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>src\flow\controller\task.js</title>
  
    <link rel="stylesheet" href="../assets/vendor/prettify/prettify-min.css">
    <link rel="stylesheet" href="../assets/css/main.css" id="site_styles">
    <link rel="stylesheet" href="../assets/vendor/bootstrap/css/bootstrap.min.css">
    <link rel="shortcut icon" type="image/png" href="../assets/favicon.png">
</head>
<body class="yui3-smart">
 <nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
        <div class="container-fluid">
            <div class="navbar-header">
                <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
                    <span class="sr-only">Toggle navigation</span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
               <a class="navbar-brand mainlogo" href="/static/doc/index.html">
             
            <img alt="" src="../assets/css/logo.png" title="">
            
                
          </a>
            </div>
            <div id="navbar" class="navbar-collapse collapse">
                 <ul class="nav navbar-nav">
                    
                    <li><a href="/home/index/index">首页</a>
                    </li>
                    
                    <li><a href="/static/doc/index.html">文档</a>
                    </li>
                    
                    <li><a href="/admin/index/index">演示</a>
                    </li>
                    
                    <li><a href="/home/index/log">日志</a>
                    </li>
                    
                </ul>
               <div class="navbar-form navbar-right filterAPi" autocomplete="off">
                <input type="text" id='txtSearchAPI' class="form-control search-query" placeholder="Search for API" />
                 <ul id="filterList" class="filterItems dropdown-menu" role="menu"></ul>
                </div>
            </div>
        </div>
    </nav>
    <div id="sidebar">
    <h3>Modules/Classes</h3>
        <div id="api-tabview-filter">
            <input id='txtSearch' type="search" class="form-control" placeholder="Type to filter Modules/Classes">
        </div>
        <dl id="sidebar_list">
             
                <dt>
                    <span class="glyphicon glyphicon-minus"></span>
                    <a href="../modules/admin.controller.html">admin.controller</a>
                </dt>
                <dd>
                    <ul>
                   
                       <li>
                            
                           <a href="../classes/admin.controller.base.html">admin.controller.base</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/admin.controller.code.html">admin.controller.code</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/admin.controller.index.html">admin.controller.index</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/admin.controller.mob.html">admin.controller.mob</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                    </ul>
                </dd>
             
                <dt>
                    <span class="glyphicon glyphicon-minus"></span>
                    <a href="../modules/admin.model.html">admin.model</a>
                </dt>
                <dd>
                    <ul>
                   
                       <li>
                            
                           <a href="../classes/admin.model.code.html">admin.model.code</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/admin.model.code_list.html">admin.model.code_list</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/admin.model.code_lookup.html">admin.model.code_lookup</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/admin.model.groupuser.html">admin.model.groupuser</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/admin.model.groupuser_add.html">admin.model.groupuser_add</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/admin.model.log.html">admin.model.log</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/admin.model.login.html">admin.model.login</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/admin.model.privilege.html">admin.model.privilege</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/admin.model.teamuser.html">admin.model.teamuser</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/admin.model.teamuser_add.html">admin.model.teamuser_add</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/admin.model.user.html">admin.model.user</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                    </ul>
                </dd>
             
                <dt>
                    <span class="glyphicon glyphicon-minus"></span>
                    <a href="../modules/cmpage.controller.html">cmpage.controller</a>
                </dt>
                <dd>
                    <ul>
                   
                       <li>
                            
                           <a href="../classes/cmpage.controller.base.html">cmpage.controller.base</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/cmpage.controller.mob.html">cmpage.controller.mob</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/cmpage.controller.module.html">cmpage.controller.module</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/cmpage.controller.page.html">cmpage.controller.page</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/cmpage.controller.utils.html">cmpage.controller.utils</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                    </ul>
                </dd>
             
                <dt>
                    <span class="glyphicon glyphicon-minus"></span>
                    <a href="../modules/cmpage.logic.html">cmpage.logic</a>
                </dt>
                <dd>
                    <ul>
                   
                       <li>
                            
                           <a href="../classes/cmpage.logic.page.html">cmpage.logic.page</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                    </ul>
                </dd>
             
                <dt>
                    <span class="glyphicon glyphicon-minus"></span>
                    <a href="../modules/cmpage.model.html">cmpage.model</a>
                </dt>
                <dd>
                    <ul>
                   
                       <li>
                            
                           <a href="../classes/cmpage.model.area.html">cmpage.model.area</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/cmpage.model.base.html">cmpage.model.base</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/cmpage.model.file_list.html">cmpage.model.file_list</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/cmpage.model.page.html">cmpage.model.page</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/cmpage.model.page_excel.html">cmpage.model.page_excel</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/cmpage.model.page_lookup.html">cmpage.model.page_lookup</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/cmpage.model.page_mob.html">cmpage.model.page_mob</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/cmpage.model.utils.html">cmpage.model.utils</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/cmpage.cmpage_global.html">cmpage.cmpage_global</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/cmpage.cmpage_global_flow.html">cmpage.cmpage_global_flow</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                    </ul>
                </dd>
             
                <dt>
                    <span class="glyphicon glyphicon-minus"></span>
                    <a href="../modules/demo.model.html">demo.model</a>
                </dt>
                <dd>
                    <ul>
                   
                       <li>
                            
                           <a href="../classes/flow.model.proc_assign.html">flow.model.proc_assign</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/cmpage.model.appr.html">cmpage.model.appr</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/flow.model.proc.html">flow.model.proc</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/flow.model.task.html">flow.model.task</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/flow.model.task_act.html">flow.model.task_act</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/flow.model.task_act_appr.html">flow.model.task_act_appr</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                    </ul>
                </dd>
             
                <dt>
                    <span class="glyphicon glyphicon-minus"></span>
                    <a href="../modules/flow.controller.html">flow.controller</a>
                </dt>
                <dd>
                    <ul>
                   
                       <li>
                            
                           <a href="../classes/flow.controller.act.html">flow.controller.act</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/flow.controller.base.html">flow.controller.base</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/flow.controller.proc.html">flow.controller.proc</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/flow.controller.task.html">flow.controller.task</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/flow.controller.task_act.html">flow.controller.task_act</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                    </ul>
                </dd>
             
                <dt>
                    <span class="glyphicon glyphicon-minus"></span>
                    <a href="../modules/flow.model.html">flow.model</a>
                </dt>
                <dd>
                    <ul>
                   
                       <li>
                            
                           <a href="../classes/flow.model.act.html">flow.model.act</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/flow.model.act_path.html">flow.model.act_path</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                    </ul>
                </dd>
             
        </dl>
</div>
   
    <div class="stdoc-content">
        <!--     <form id="options-form" class="form-inline pull-right">
        Show:
        <label for="api-show-inherited" class="checkbox">
            <input type="checkbox" id="api-show-inherited" checked>
            Inherited
        </label>

        <label for="api-show-protected" class="checkbox">
            <input type="checkbox" id="api-show-protected">
            Protected
        </label>

        <label for="api-show-private" class="checkbox">
            <input type="checkbox" id="api-show-private">
            Private
        </label>
        <label for="api-show-deprecated" class="checkbox">
            <input type="checkbox" id="api-show-deprecated">
            Deprecated
        </label>

    </form>

 -->
        <div class="apidocs">
            <div id="docs-main">
                <div class="content">
                    <div class="page-header">
    <h1>src\flow\controller\task.js <small>File</small></h1>
</div>

<div class="file">
    <pre class="prettyprint linenums" id='src_code'>
&#x27;use strict&#x27;;

/**
 * 提供工作流模板设计的URL接口&lt;br/&gt;
 * 提供工作流引擎的URL调用接口
 * @class flow.controller.task
 */
import Base from &#x27;./base.js&#x27;;

export default class extends Base {
    /**
     * 启动一个新的流程实例, GET调用：/flow/task/start?procID=xxx
     * @method  start
     * @return {json}  流程实例对象
     */
    async startAction(){
        let procID = this.get(&#x27;procID&#x27;);
        let ret = {statusCode:300,message:&#x27;流程模板不存在或设置有错误!&#x27;,task:{}};

        let procModel = this.model(&#x27;proc&#x27;);
        await procModel.fwInit(0,await this.session(&#x27;user&#x27;),procID);
        await procModel.fwStart();

        let task = procModel.taskModel.task;
        let currAct = procModel.taskModel.currAct;
        let currTaskAct = procModel.taskModel.currTaskAct;
        if(think.isEmpty(task) || task.id ===0){
//            ret.message = task.message;
            return this.json(ret);
        }
        let utilsModel = this.model(&#x27;cmpage/utils&#x27;);
        ret = {statusCode:200,message:&#x60;流程已经${await utilsModel.getEnumName(task.c_status,&#x27;TaskStatus&#x27;)}!&#x60;,task:task, currAct:currAct, currTaskAct:currTaskAct};
        if(task.c_status === cmpage.enumTaskStatus.RUN){
            ret.message = &#x60;当前节点:${await this.model(&#x27;act&#x27;).getNameById(currAct.id)},
                            状态${await utilsModel.getEnumName(currAct.c_status,&#x27;TaskActStatus&#x27;)}&#x60;;
            if(currTaskAct.c_status === cmpage.enumTaskActStatus.WAIT &amp;&amp; !think.isEmpty(currAct.c_form)){
                //根据设定弹出相关界面
                debug(currAct,&#x27;c:task.start - currAct - 弹出界面&#x27;);
                currAct.form =eval(&quot;(&quot;+ currAct.c_form +&quot;)&quot;);  // JSON.parse(currAct.c_form);
                if(!think.isEmpty(currAct.form[&#x27;modulename&#x27;])){
                    currAct.form.url = &#x60;/cmpage/page/edit?modulename=${currAct.form[&#x27;modulename&#x27;]}&amp;id=0&amp;taskID=${task.id}&amp;taskActID=${currTaskAct.id}&amp;status=${currAct.c_domain_st}&#x60;;
                }
                currAct.form.url = currAct.form.url.replace(/#taskID#/g,task.id).replace(/#taskActID#/g,currAct.id);
                currAct.form.opentype = think.isEmpty(currAct.form[&#x27;opentype&#x27;]) ? &#x27;dialog&#x27;:currAct.form[&#x27;opentype&#x27;];
                currAct.form.id = think.isEmpty(currAct.form[&#x27;id&#x27;]) ? &#x27;fwTaskAct&#x27;+currAct.id:currAct.form[&#x27;id&#x27;];
                currAct.form.title = think.isEmpty(currAct.form[&#x27;title&#x27;]) ? currAct.c_name:currAct.form[&#x27;title&#x27;];
                currAct.form.height = think.isEmpty(currAct.form[&#x27;height&#x27;]) ? 400:currAct.form[&#x27;height&#x27;];
                currAct.form.mask = true;
                ret.task = task;
                ret.currAct = currAct;
            }
        }

        //TODO: 根据任务的当前状态分别处理,其他的让前端处理

        return this.json(ret);
    }

    /**
     * 重新运行一个流程实例, GET调用：/flow/task/run?task_id=xxx
     * @method  run
     * @return {json}  流程实例对象
     */
    async runAction(){
        let user = await this.session(&#x27;user&#x27;);
        let taskID = this.get(&#x27;taskID&#x27;);
        let procModel = this.model(&#x27;proc&#x27;);
        await procModel.fwInit(procID,await this.session(&#x27;user&#x27;));

        let task = await this.model(&#x27;proc&#x27;).fwRun(taskID,user);

        return this.json({statusCode:200,message:&#x27;流程重新运行成功!&#x27;,task:task});
    }

    /**
     * 挂起一个流程实例, GET调用：/flow/task/suspend?task_id=xxx
     * @method  suspend
     * @return {json}  流程实例对象
     */
    async suspendAction(){
        let user = await this.session(&#x27;user&#x27;);
        let taskID = this.get(&#x27;taskID&#x27;);

        let task = await this.model(&#x27;proc&#x27;).fwSuspend(taskID,user);

        return this.json({statusCode:200,message:&#x27;流程已成功挂起!&#x27;,task:task});
    }

    /**
     * 终止一个流程实例, GET调用：/flow/task/terminate?task_id=xxx
     * @method  terminate
     * @return {json}  流程实例对象
     */
    async terminateAction(){
        let user = await this.session(&#x27;user&#x27;);
        let taskID = this.get(&#x27;taskID&#x27;);

        let task = await this.model(&#x27;proc&#x27;).fwTerminate(taskID,user);

        return this.json({statusCode:200,message:&#x27;流程已成功终止!&#x27;,task:task});
    }

    /**
     * 自动执行, GET调用：/flow/task/auto_exec
     * @method  autoExec
     * @return {json}  状态消息
     */
    async autoExecAction(){
        if(!cmpage.flow.autoExecuting){
            cmpage.flow.autoExecuting =true;
            await this.model(&#x27;act&#x27;).fwAutoExec();
            cmpage.flow.autoExecuting =false;
            return this.json({statusCode:200,message:&#x27;流程的自动执行操作成功!&#x27;});
        }
        return this.json({statusCode:200,message:&#x27;流程正在自动执行中......&#x27;});
    }

    flowAction(){
        let parms = this.get();
        this.assign(&#x27;parms&#x27;,parms);
        return this.display();
    }

    async flowMapAction(){
        let taskID = this.get(&quot;taskID&quot;);
        let flowMap = await this.model(&#x27;task&#x27;).getFlowMap(taskID);
        this.assign(&#x27;flowMap&#x27;,flowMap);

        return this.display();
    }
}

    </pre>
</div>

                </div>
            </div>
        </div>
    </div>
<a id="gotoTop" class='well well-small' href='#'>
    Top
</a>
<script src="../assets/vendor/jquery/jquery-1.8.2.min.js"></script>
<script src="../assets/vendor/bootstrap/js/bootstrap.min.js"></script>
<script src="../assets/vendor/prettify/prettify-min.js"></script>
<script src="../assets/js/config.js"></script>
<script src="../assets/js/doc.js"></script>
</body>
</html>
